<?php

// 删除项目
// DELETE project.delete

namespace app\api\resource\project;
use think\Db;
use think\Session;

class Delete
{
    // 方法
    public $_method = ['DELETE'];
    // 前置
    public $_pre    = ['login','isCyz'];
    // 描述
    public $_description = '删除项目';
    // 参数
    public $_param  = [
        'project_id' => '项目主键',
    ];
    // 返回
    public $_return = [
        204 => '删除成功',
        404 => '项目不存在',
        422 => '项目主键必须',
        500 => '服务器异常',
    ];

    public function run(&$request)
    {
        $projectId = $request->delete('project_id/d',0);

        if (0 == $projectId) return [422,'项目主键必须'];
        
        $memberId = Session::get('member.id');

        $project = Db::name('project')->where('id',$projectId)->where('member_id',$memberId)->find();

        if ( is_null($project) ) return [404,'项目不存在'];

        $data['delete_time'] = time();
        $num = Db::name('project')->where('id',$projectId)->update($data);

        return ($num > 0) ? [ 204,'' ] : 500;
    }
}